package com.approval.approvalapp.center.centerfragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.approval.approvalapp.MyAppliaction;
import com.approval.approvalapp.R;
import com.approval.approvalapp.login.LoginActivity;
import com.approval.approvalapp.myself.activity.WdHysSqActivity;
import com.approval.approvalapp.myself.activity.WdkqActivity;
import com.approval.approvalapp.myself.activity.WdqjActivity;
import com.approval.approvalapp.myself.activity.WdwzActivity;
import com.approval.approvalapp.util.SpUtil;
import com.approval.approvalapp.util.base.BaseFragment;
import com.bumptech.glide.Glide;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * A simple {@link Fragment} subclass.
 */
public class CenterMySelfFragment extends BaseFragment {


    @Bind(R.id.name_tv)
    TextView nameTv;
    @Bind(R.id.dw_tv)
    TextView dwTv;
    @Bind(R.id.wdqj_rl)
    RelativeLayout wdqjRl;
    @Bind(R.id.wdwz_rl)
    RelativeLayout wdwzRl;
    @Bind(R.id.hysyd_rl)
    RelativeLayout hysydRl;
    @Bind(R.id.wdkq_rl)
    RelativeLayout wdkqRl;
    @Bind(R.id.exit_rl)
    RelativeLayout exitRl;
    @Bind(R.id.civ)
    CircleImageView civ;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_center_my_self;
    }

    @Override
    public void initView(View view) {
        nameTv.setText(SpUtil.getString(MyAppliaction.getInstance(), SpUtil.USER_RUN_NICKNAME, ""));
        dwTv.setText(SpUtil.getString(MyAppliaction.getInstance(), SpUtil.UNIT_NAME, ""));

    }

    @Override
    public void initData() {
        Glide.with(this.getActivity()).load(SpUtil.getString(this.getActivity(),SpUtil.USER_AVATER,""))
                .into(civ);

    }


    @OnClick({R.id.wdqj_rl, R.id.wdwz_rl, R.id.hysyd_rl, R.id.wdkq_rl, R.id.exit_rl})
    public void onViewClicked(View view) {
        Intent intent = new Intent();
        switch (view.getId()) {
            case R.id.wdqj_rl:
                intent.setClass(this.getActivity(), WdqjActivity.class);
                startActivity(intent);
                break;
            case R.id.wdwz_rl:
                intent.setClass(this.getActivity(), WdwzActivity.class);
                startActivity(intent);
                break;
            case R.id.hysyd_rl:
                intent.setClass(this.getActivity(),WdHysSqActivity.class);
                startActivity(intent);
                break;
            case R.id.wdkq_rl:
                intent.setClass(this.getActivity(), WdkqActivity.class);
                startActivity(intent);
                break;
            case R.id.exit_rl:
                //退出登录 修改配置
                SpUtil.saveString(MyAppliaction.getInstance(), SpUtil.USER_RUN_ID, "-1");
                SpUtil.saveString(MyAppliaction.getInstance(), SpUtil.CENCACHE, "");
                this.getActivity().finish();
                intent.setClass(this.getActivity(), LoginActivity.class);
                startActivity(intent);
                break;
        }
    }
}
